package com.gemme.gemme.login;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.MainActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.adapter.StrGuigeAdapter;
import com.gemme.gemme.util.DpUtil;
import com.gemme.gemme.util.SPUtil;
import com.gemme.gemme.util.ShapeUtil;
import com.gemme.gemme.view.InterestView;
import com.gemme.gemme.view.MyButton;
import com.gemme.gemme.view.Topview;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;
import com.luck.picture.lib.tools.SPUtils;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;

//侧滑删除地址
public class IntersetActivity extends BaseActivity implements InterestView.OnSelectChange {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getData();
        setContentView(R.layout.activity_interest);
        StatusBarUtil.setTransparent(this);
//        judge();
        initView();

    }

    private void judge() {
        //todo 有登陆信息直接进入主页
        String ACCESS_TOKEN = SPUtil.getDataForString(mContext, Constant.ACCESS_TOKEN, "");

        if(!TextUtils.isEmpty(ACCESS_TOKEN)){
            startActivity(new Intent(this, MainActivity.class));
            finish();
            return;
        }

       /* String dataForString = SPUtil.getDataForString(mContext, Constant.isFirstLogin, "0");
        if("0".equals(dataForString)){
            SPUtil.PutData(mContext,Constant.isFirstLogin,"-1");
            SPUtil.getDataForString(mContext, Constant.isFirstLogin, "0");
        }else{
            startActivity(new Intent(this,LoginNewActivity.class));
            finish();
        }*/

        startActivity(new Intent(this,LoginNewActivity.class));
    }



    private void getData() {
        try {
            String dataForString = SPUtil.getDataForString(mContext, Constant.IntersetNUmString, "");
            if(!TextUtils.isEmpty(dataForString)){
                //有数据跳到下一页
            }

        }catch (Exception e){

        }
    }

    //    InterestView
    MyButton button1;
    TextView tv_skip;

    ArrayList<InterestView> viewList = new ArrayList<InterestView>();
    private void initView() {

        ArrayList<String> list = new ArrayList<>();
        LinearLayout ll_content = findViewById(R.id.ll_content);
        button1 = findViewById(R.id.button1);

        tv_skip = findViewById(R.id.tv_skip);
        button1.setSatate(false);
        list.add("口红");
        list.add("香氛");
        list.add("护肤");
        list.add("男士");
        list.add("彩妆");
        list.add("卸妆");
        list.add("睫毛膏");
        list.add("眼影眼线");
        list.add("化妆工具");

        //1 2 3   3
        LinearLayout linearLayout = null;
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        int diff = DpUtil.dp2px(mContext, 10);
//        params.setMargins(10,10,10,10);
        for (int i = 0; i < list.size(); i++) {
            InterestView interestView = new InterestView(mContext);
            interestView.setContent(list.get(i));
            if( ((i + 1) % 3) == 1 ){
                linearLayout = new LinearLayout(mContext);
                ll_content.addView(linearLayout);
                params.setMargins(0,diff,0,0);
                interestView.setLayoutParams(params);
            }

            if ( ((i + 1) % 3) == 2 ||  ((i + 1) % 3) == 0 ){
                params.setMargins(diff,diff,0,0);
                interestView.setLayoutParams(params);
            }
            linearLayout.addView(interestView);

            viewList.add(interestView);

            interestView.setOnSelectChange(this);
        }

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext,SexAgeActivity.class));
            }
        });

        tv_skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext,SexAgeActivity.class));
                finish();
            }
        });
    }

    ArrayList<String> selectValueList= new ArrayList<String>();
    @Override
    public void onSelectChange() {
        selectValueList.clear();
        for (InterestView interestView : viewList) {
            if(interestView.getSelect()){
                selectValueList.add(interestView.getContent());
            }
        }

        button1.setText("请至少关注三个感兴趣("+selectValueList.size()+"/3)");
        if(selectValueList.size() >= 3){
            button1.setSatate(true);
        }else{
            button1.setSatate(false);
        }
        SPUtil.PutData(mContext,Constant.IntersetNUmString, JSON.toJSONString(selectValueList));
        String dataForString = SPUtil.getDataForString(mContext, Constant.IntersetNUmString, "");
        System.out.println("");
    }
}